package com.kedi.usercenter.utils;

import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;


import java.util.Date;
import java.util.Map;

/**
* @Description:    jwt工具类
* @Author:         ytw
* @CreateDate:     2019/7/30 0:40
* @UpdateRemark:   修改内容
* @Version:        1.0
*/
public class JwtUtils {


    public static final String SUBJECT = "kedi";

    public static final long EXPIRE = 1000*60*60*24*7;


    public static final  String APPSECRET = "kedi999";

 /**
 * 方法实现说明  生成jwt
 * @author      ytw
 *@param
 * @return
 * @exception
 * @date        2019/7/30 0:42
 */
    public static String geneJsonWebToken(Map map){

        String token = Jwts.builder().setSubject(SUBJECT)
                .claim("id",map.get("id"))
                .claim("name",map.get("name"))
                .claim("idcard",map.get("idcard"))
                .setIssuedAt(new Date())
                .setExpiration(new Date(System.currentTimeMillis()+EXPIRE))
                .signWith(SignatureAlgorithm.HS256,APPSECRET).compact();
        return token;
    }


  /**
  * 方法实现说明  校验token
  * @author      ytw
  *@param        token
  * @return
  * @exception
  * @date        2019/7/30 0:42
  */
    public static Claims checkJWT(String token){

        try{
            final Claims claims =  Jwts.parser().setSigningKey(APPSECRET).
                    parseClaimsJws(token).getBody();
            return  claims;

        }catch (Exception e){ }
        return null;

    }



}
